import { defineStore } from 'pinia'
import { listSession, getSession, getSessionMessages } from '@/api/system/session'

export const useSessionStore = defineStore('session', {
  state: () => ({
    sessionList: [],
    currentSession: null,
    messages: [],
    loading: false,
    total: 0
  }),

  actions: {
    // 获取会话列表
    async fetchSessionList(query) {
      this.loading = true
      try {
        const response = await listSession(query)
        this.sessionList = response.rows
        this.total = response.total
        return response
      } finally {
        this.loading = false
      }
    },

    // 获取单个会话详情
    async fetchSession(sessionId) {
      const response = await getSession(sessionId)
      this.currentSession = response.data
      return response.data
    },

    // 获取会话消息记录
    async fetchSessionMessages(sessionId) {
      const response = await getSessionMessages(sessionId)
      this.messages = response.data
      return response.data
    },

    // 清除当前会话数据
    clearCurrentSession() {
      this.currentSession = null
      this.messages = []
    }
  }
}) 